package com.batch.adance;
import java.util.Arrays;
import java.util.List;

import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.item.ItemWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

//@Configuration
public class InputOverViewDemoJobConfiguration {
    @Autowired
    private JobBuilderFactory jobBuilderFactory;
    @Autowired
    private StepBuilderFactory stepBuilderFactory;

    @Bean
    public Job inputOverViewDemoJob() {
        return jobBuilderFactory.get("inputOverViewDemoJob").start(inputOverViewDemoJobStep()).build();

    }

    public Step inputOverViewDemoJobStep() {
        return stepBuilderFactory.get("inputOverViewDemoJobStep").<String, String>chunk(2)
                .reader(inputOverViewDemoReader()).writer(outputOverViewDemoWriter()).build();
    }

    private ItemWriter<? super String> outputOverViewDemoWriter() {
        return new ItemWriter<String>() {

            @Override
            public void write(List<? extends String> items) throws Exception {
                for (String item : items) {
                    System.out.println("output writer data: " + item);
                }
            }
        };
    }

    @Bean
    public InputOverVierDemoItemReader inputOverViewDemoReader() {
        List<String> data = Arrays.asList("dazhonghua", "xiaoriben", "meilijian", "falanxi", "deyizhi", "aierlan",
                "fandigang", "bajisitan", "baieluosi");
        return new InputOverVierDemoItemReader(data);
    }
}
